package cn.schoolwow.workflow.module.common.flow;

import cn.schoolwow.quickdao.domain.database.dql.condition.Condition;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.domain.task.ContextDataQuery;

import java.util.List;

public class AddContextDataQueryFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        List<ContextDataQuery> contextDataQueryList = flowContext.getData("contextDataQueryList", List.class);
        if(null==contextDataQueryList||contextDataQueryList.isEmpty()){
            return;
        }
        Condition condition = flowContext.checkInstanceData(Condition.class);

        for(ContextDataQuery contextDataQuery: contextDataQueryList){
            condition.addJSONQuery("contextData",contextDataQuery.fieldName,contextDataQuery.operator,contextDataQuery.value);
        }
    }

    @Override
    public String name() {
        return "添加实例上下文数据查询";
    }
}
